package com.kaisu.blog.application.blog.convert;

import com.kaisu.blog.application.blog.dto.BlogDTO;
import com.kaisu.blog.application.blog.dto.BlogPageDTO;
import com.kaisu.blog.application.blog.dto.CommentPageDTO;
import com.kaisu.blog.application.file.convert.FileApplicationConvert;
import com.kaisu.blog.application.user.convert.UserApplicationConvert;
import com.kaisu.blog.domain.blog.Blog;
import com.kaisu.blog.domain.blog.Comment;
import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

/**
 * @author kaisu
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = {FileApplicationConvert.class, UserApplicationConvert.class})
@DecoratedWith(BlogApplicationConvertDecorated.class)
public interface BlogApplicationConvert {
    @Mapping(target = "like", ignore = true)
    @Mapping(target = "likeCount", expression = "java((long) domain.getLikes().size())")
    @Mapping(target = "cover", source = "cover.previewPath")
    BlogPageDTO toPageDTO(Blog domain);

    @Mapping(target = "like", ignore = true)
    @Mapping(target = "likeCount", expression = "java((long) domain.getLikes().size())")
    @Mapping(target = "cover", source = "cover.previewPath")
    BlogDTO toDTO(Blog domain);

    CommentPageDTO toPageDTO(Comment domain);
}
